package com.five.wisdomClass.controller;

import com.five.wisdomClass.bean.ResponseData;
import com.five.wisdomClass.entity.*;
import com.five.wisdomClass.service.ITeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


@Tag(name="教师的基本操作")
@Slf4j
@RestController
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/teacher")
public class TeacherController extends BaseController{

    private final ITeacherService teacherService;

    @Operation(summary = "获取课程表")
    @GetMapping("/getcourses")
    public ResponseData<Object> getCourses(String teacherNumber){
        return returnObject(teacherService.getCourses(teacherNumber));
    }

    @Operation(summary = "获取课程中的学生")
    @GetMapping("/getstudents")
    public ResponseData<Object> getStudents(Integer currentPage,Integer size,String courseNumber){
        return returnObject(teacherService.getCourseStudents(currentPage,size,courseNumber));
    }
    @Operation(summary = "获取课程中的学生请假列表")
    @GetMapping("/getcoursestudentleave")
    public ResponseData<Object> getCourseStudentsLeave(Integer currentPage,Integer size,String courseNumber){
        return returnObject(teacherService.getCourseStudentLeave(currentPage,size,courseNumber));
    }


    @Operation(summary = "发布签到")
    @PostMapping("/postsignin")
    public ResponseData<Boolean> postSignIn(@RequestBody Course course){
        if (course.getCourseNumber().isEmpty()){
            return null;
        }
        return returnBoolean(teacherService.postSignIn(course));
    }

    @Operation(summary = "获取所教课程")
    @GetMapping("/getteachcourses")
    public ResponseData<Object> getTeachCourses(String teacherNumber){
        if (teacherNumber.isEmpty()){
            return null;
        }
        return returnObject(teacherService.getTeachCourses(teacherNumber));
    }

    @Operation(summary = "查看某课程发布的签到记录")
    @GetMapping("/getpostsigninfo")
    public ResponseData<Object> getPostSignInfo(Integer currentPage, Integer size,String courseNumber){
        if (courseNumber.isEmpty()){
            return null;
        }
        return returnObject(teacherService.getSignInfo(currentPage,size,courseNumber));
    }

    @Operation(summary = "查看签到的学生")
    @GetMapping("/getsignstudents")
    public ResponseData<Object> getSignStudents(Integer currentPage, Integer size, String postTime){
        return returnObject(teacherService.getSignStudents(currentPage,size,postTime));
    }

    @Operation(summary = "查看未签到的学生")
    @GetMapping("/getunsignstudents")
    public ResponseData<Object> getUnSignStudents(Integer currentPage, Integer size,String postTime){
        return returnObject(teacherService.getUnSignStudents(currentPage,size,postTime));
    }

    @Operation(summary = "发布课程")
    @PostMapping("/insertCourse")
    public ResponseData<Boolean> insertCourse(@RequestBody Course course){
        if (course.getCourseNumber().isEmpty()){
            return null;
        }
        return returnBoolean(teacherService.insertCourse(course));
    }


    @Operation(summary = "获取某门课程的课程情况")
    @GetMapping("/getOneCourseInfo")
    public ResponseData<Object> getOneCourseInfo(Integer currentPage, Integer size,String courseNumber){
        return returnObject(teacherService.getOneCourseInfo(currentPage,size,courseNumber));
    }

    @Operation(summary = "调整某堂课程")
    @PutMapping("/updatecourse")
    public ResponseData<Boolean> deletePlan(@RequestBody Course course){
        if (course.getId() == null || course.getCourseNumber() == null || course.getStartTime() == null || course.getEndTime() == null || course.getLocation() ==null){
            return null;
        }
        return returnBoolean(teacherService.updateCourse(course));
    }

    @Operation(summary = "通过时间搜索课程")
    @GetMapping("/getCourseByDate")
    public ResponseData<Object> getCourseByDate(Integer currentPage,Integer size,String time,String courseNumber){
        if (time == null || courseNumber == null ){
            return null;
        }
        // 如果选修课不为空
        if (teacherService.selectTakeCourseByDate(currentPage,size,time,courseNumber) != null){
            return returnObject(teacherService.selectTakeCourseByDate(currentPage,size,time,courseNumber));
        }
        // 如果公共课不为空
        if (teacherService.selectPublicCourseByDate(currentPage,size,time,courseNumber) != null){
            return returnObject(teacherService.selectPublicCourseByDate(currentPage,size,time,courseNumber));
        }
        return null;
    }
}
